/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;


import Entitys.Pedido;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author MAURO
 */
public class PedidoServices {
    EntityManagerFactory emf= Persistence.createEntityManagerFactory("DrugStoreProPU");
         EntityManager em=emf.createEntityManager();
         
         
         
         public void delete (Integer   i){
          em.getTransaction().begin();
          Pedido p1=em.find(Pedido.class, i);
          if(p1!= null)
          em.remove(p1);
          em.getTransaction().commit();
          em.close();
         }
         
         public List<Pedido> readAll(){
           Query q= em.createNamedQuery("Pedido.findAll");
           return q.getResultList();
         }

    public Pedido ReadById(Object idpe){
             Query q= em.createNamedQuery("Pedido.findByIdPedido");
             q.setParameter("idPedido", idpe);
             
             return (Pedido) q.getSingleResult();
         }

   
   
}
